#include <my_head.h>

int main(int argc, const char *argv[]){
    FILE *fp = NULL;
    if(NULL == (fp = fopen("hello.txt", "w+")))
        ERR_LOG("fopen error");
    // 1.写入整数
        int x1 = 1234;
        fwrite(&x1, 1, 4, fp);
        fseek(fp, 0, SEEK_SET);// 重置光标到文件开头
        int x2 = 0;
        fread(&x2, 1, 4, fp);
        printf("x2 = [%d]\n", x2); // 1234
    // 2.写入字符串
        rewind(fp);// 重置光标到文件开头
        char buff[20] = "hello world";
        fwrite(buff, 1, 11, fp);
        fseek(fp, 0, SEEK_SET);// 重置光标到文件开头
        char buff2[20] = {0};
        fread(buff2, 1, sizeof(buff2), fp);
        printf("buff2 = [%s]\n", buff2); // hello world
    fclose(fp);
    return 0;
}